import { get } from "../../utils/db"
Page({
    data: {
        types: [
            {
                src: "../../imgs/index_07.jpg",
                typename: "营养菜谱"
            },
            {
                src: "../../imgs/index_09.jpg",
                typename: "儿童菜谱"
            },
        ],
        list: [],//菜谱列表        20条数据
        page: 1,         //第几页
        pageSize: 10,            //每一页多少内容
    },
    //页面加载，获取第1页内容
    onLoad() {
        //获取菜谱列表
        this.getList()
    },
    //页面触底
    onReachBottom(){
        this.data.page++;           //页码累加   3
        this.getList()

    },
    //获取菜谱列表
    async getList() {
        let pageSize = this.data.pageSize           //10
        let skip = (this.data.page - 1) * pageSize   //20

        let result = await get({ collection: "menu", skip: skip, limit: pageSize }).catch(err => {
            console.error(err)
        })
        this.setData({
            list: this.data.list.concat(result.data) 
        })
    },
    //跳转详情页
    toDetail(e){
        let id=e.currentTarget.id;      //菜谱id
        wx.navigateTo({
          url: '/pages/detail/detail?id='+id,
        })
    }
    
})